Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP 8.2] Fixed deprecation error for creation of dynamic property #3177

Merged
merged 4 commits into from
Apr 18, 2023
Merged

[PHP 8.2] Fixed deprecation error for creation of dynamic property #3177

merged 4 commits into from
Apr 18, 2023

Conversation

fballiano
Copy link
Contributor

After #2759, when visiting a product page or the cart page (with developer mode) we get:

Deprecated functionality: Creation of dynamic property Mage_Paypal_Model_Config::$visible_on_product is deprecated in app/code/core/Mage/Paypal/Model/Config.php on line 781"

This PR partially reverts #2759 but only for 2 specific properties

How to test:

  • enable developer mode
  • visit product page or cart

@github-actions github-actions bot added the Component: PayPal Relates to Mage_Paypal label Apr 15, 2023
addison74
addison74 previously approved these changes Apr 15, 2023
@elidrissidev
Copy link
Member

The thing is, <visible_on_cart> and <visible_on_product> are in Paypal's config.xml, and if they exist as a property, __get will not be called and a null value will be retrieved every time. But since the __get method is setting them dynamically, I think there's no way around it other than to refactor the method.

@elidrissidev
Copy link
Member

An alternative approach could be to use array instead (untested):

     public function __get($key)
     {
+        if (array_key_exists($this->_config, $key)) {
+            return $this->_config[$key];
+        }
+
         $underscored = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $key));
         $value = Mage::getStoreConfig($this->_getSpecificConfigPath($underscored), $this->_storeId);
         $value = $this->_prepareValue($underscored, $value);
-        $this->$key = $value;
-        $this->$underscored = $value;
+        $this->_config[$key] = $value;
+        $this->_config[$underscored] = $value;
         return $value;
     }

@addison74 addison74 linked an issue Apr 15, 2023 that may be closed by this pull request
@fballiano
Copy link
Contributor Author

@elidrissidev your solution is much better, you want to commit it or should I do it?

@elidrissidev
Copy link
Member

I won't have the chance now, you can do it if you're free.

@fballiano
Copy link
Contributor Author

I can never make a sandbox paypal account work but I've reworked this PR, I thought to check _config also for the underscored key... what do you think?

Copy link
Member

@elidrissidev elidrissidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested. Accessing properties works fine and no more deprecation errors.

@fballiano fballiano merged commit 177461b into OpenMage:main Apr 18, 2023
@fballiano fballiano deleted the paypal82 branch April 18, 2023 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: PayPal Relates to Mage_Paypal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

system.log - Errors and Warnings
3 participants